#include <bits/stdc++.h>
using namespace std;

class Solution {
	const int MOD = 1e9 + 7;
	const int RED = 0, GREEN = 1, BLUE = 2;

	int n, m;
	vector<vector<vector<int>>> dp;

	int get(int s, int bit)
	{
		return s / bit % 3;
	}

	int set(int s, int bit, int val)
	{
		return s - get(s, bit) * bit + val * bit;
	}

	int cal(int i, int j, int s, int bit)
	{
		if (i == n) {
			return 1;
		}

		if (j == m) {
			return cal(i + 1, 0, s, 1);
		}

		if (dp[i][j][s] != -1){
			return dp[i][j][s];
                }

		int up = i == 0 ? -1 : get(s, bit);
		int left = j == 0 ? -1 : get(s, bit / 3);

		int ans = 0;
		if (up != RED && left != RED) {
			ans = (ans + cal(i, j + 1, set(s, bit, RED), bit * 3)) % MOD;
		}

		if (up != GREEN && left != GREEN) {
			ans = (ans + (cal(i, j + 1, set(s, bit, GREEN), bit * 3))) % MOD;
		}

		if (up != BLUE && left != BLUE) {
			ans = (ans + (cal(i, j + 1, set(s, bit, BLUE), bit * 3))) % MOD;
		}

		return dp[i][j][s] = ans;
	}

    public:
	int colorTheGrid(int im, int in)
	{
		Solution::n = max(im, in);
		Solution::m = min(im, in);
		dp = vector<vector<vector<int>>>(n, vector<vector<int>>(m, vector<int>(pow(3, m), -1)));
		return cal(0, 0, 0, 1);
	}
};

int main()
{
        int im = 2, in = 3;
        cout << Solution().colorTheGrid(im, in) << endl;
        return 0;
}